﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for UsersDB
/// </summary>
public class UsersDB
{
    public int IdUser;
    
    public string Email;
    public string Password;
    public string Name;
    public string Phone;
    public double Credit;


    public enum Type
    {
        User = 0,
        Admin = 1
        
    }


	public UsersDB()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    //public static UsersDB Login(String email, String password)
    //{



    //    using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings[1].ConnectionString))
    //    {
            
    //        string sql = "SELECT *  FROM users where email = @email and password= @passowrd";
    //        SqlCommand myCommand = new SqlCommand
    //                                   {
    //                                       Connection = myConnection,
    //                                       CommandText = sql,
    //                                       CommandType = CommandType.Text
    //                                   };
        
        
        
    //    myCommand.Parameters.AddWithValue("@email", email);
    //    myCommand.Parameters.AddWithValue("@password", password);

    //    }
                                              

	
		
		
    //    if (!string.IsNullOrEmpty(loginEmail) & !string.IsNullOrEmpty(loginPassword)) {
    //        sql += "WHERE userEmail=@login and userPassword=@password";
    //        myCommand.CommandText = sql;
			
    //        myCommand.Parameters("@login").Value = loginEmail;
    //        myCommand.Parameters.Add(new SqlParameter("@password", SqlDbType.VarChar, 100));
    //        myCommand.Parameters("@password").Value = loginPassword;
    //    } else if (!string.IsNullOrEmpty(loginEmail) & string.IsNullOrEmpty(loginPassword)) {
    //        sql += "WHERE users.userEmail=@userEmail";
    //        myCommand.CommandText = sql;
    //        myCommand.Parameters.Add(new SqlParameter("@userEmail", SqlDbType.NVarChar, 100));
    //        myCommand.Parameters("@userEmail").Value = loginEmail;
    //    } else {
    //        sql += "WHERE users.idUser=@idUser";
    //        myCommand.CommandText = sql;
    //        myCommand.Parameters.Add(new SqlParameter("@idUser", SqlDbType.Int));
    //        myCommand.Parameters("@idUser").Value = idUser;
    //    }


    //    SqlDataAdapter objDA = new SqlDataAdapter(myCommand);
    //    objDA.SelectCommand.CommandType = CommandType.Text;
    //    DataSet objDS = new DataSet();
    //    objDA.Fill(objDS);

    //    if (!(objDS.Tables[0].Rows.Count == 0)) {
    //        idUser = (objDS.Tables[0].Rows[0]["idUser"]);
    //        userName = (objDS.Tables[0].Rows[0]["userName"]);
    //        userEmail = (objDS.Tables[0].Rows[0]["userEmail"]);
    //        active = objDS.Tables[0].Rows[0]["active"];
    //        requirePasswordChange = objDS.Tables[0].Rows[0]["requirePasswordChange"];
    //        sessionTimeOut = objDS.Tables[0].Rows[0]["sessionTimeOut"];
    //        this.subscription = objDS.Tables[0].Rows[0]["subscription"];
    //        this.subscriptionDay = objDS.Tables[0].Rows[0]["subscriptionDay"];
    //        this.subscriptionAN = objDS.Tables[0].Rows[0]["subscriptionAN"];
    //        this.subscriptionDayAN = objDS.Tables[0].Rows[0]["subscriptionDayAN"];
    //        if (!Information.IsDBNull(objDS.Tables[0].Rows[0]["userPassword"]))
    //            userPassword = objDS.Tables[0].Rows[0]["userPassword"];
    //        if (!Information.IsDBNull(objDS.Tables[0].Rows[0]["roles"]))
    //            roles = (objDS.Tables[0].Rows[0]["roles"]);
    //        if (!Information.IsDBNull(objDS.Tables[0].Rows[0]["userType"]))
    //            userType = (objDS.Tables[0].Rows[0]["userType"]);
    //        if (!Information.IsDBNull(objDS.Tables[0].Rows[0]["idLogisticsProvider"]))
    //            idLogisticsProvider = objDS.Tables[0].Rows[0]["idLogisticsProvider"];

    //        lastOperationReturn = true;
    //        objConn.Close();
    //        return true;
    //    } else {
    //        lastOperationMessage = "This user does not exist";
    //        lastOperationReturn = false;
    //        objConn.Close();
    //        return false;
    //    }
    //}
}


 
